package com.woniuxy.hrp.provider;

import com.woniuxy.hrp.entity.PayRecord;
import org.apache.ibatis.jdbc.SQL;

/***
 * @description: 交易记录动态查询
 * @return:
 * @author Lrw
 * @date: 2022/9/7 16:35
 */
public class PayRecordSqlProvider {
    public static String getByCondition(PayRecord payRecord) {
        String sql = new SQL() {
            {
                SELECT("*");
                FROM("hrp_payrecord");
                if (payRecord.getId() != 0) {
                    WHERE("id=#{id}");
                }
//                if (payRecord.getDateTime() != null) {
//                    WHERE("datetime=#{dateTime}");
//                }
                if (payRecord.getWay()!= null) {
                    SET("way=#{way");
                }
                if (payRecord.getReservation() != null) {
                    WHERE("reservation_id=#{reservationId}");
                }
                if (payRecord.getStartTime()!=null){
                    WHERE("CONVERT ( DATETIME, DATE ) >= #{startTime}");
                }
                if (payRecord.getEndTime()!=null){
                    WHERE("CONVERT ( DATETIME, DATE ) <= #{endTime}");
                }
            }
        }.toString();
        return sql;
    }
}
